import Dialog from './Dialog'
import Vue from 'vue'

function getDialogInstance (render = undefined) {
  return Dialog.newInstance({
        closable: false,
        maskClosable: false,
        footerHide: true,
        render: render
      });
}

function confirm (options) {
  const render = ('render' in options) ? options.render : undefined;
  const instance  = getDialogInstance(render);

  instance.show(options);
}

Dialog.alert = function (a,b,c) {
  var props = {
    showCancel: !1,
    closable: !0,
    title: '温馨提示',
    content: a,
    width: 400,
    footerHide: !1,
    okText: '确定'
  }
  b && typeof b === 'function' && (c = b)
  b && typeof b === 'object' && (props = Vue.util.extend(props,b))
  c && (props.onOk = c)
  return confirm(props)
}

Dialog.open = function (props = {}) {
  props.showCancel = true;
  props.closable = true;
  props.footerHide = false;
  return confirm(props);
}

Dialog.start = function (a,b,c,iconType) {
  var props = {
    showCancel: !1,
    icon: iconType,
    closable: !0,
    title: '温馨提示',
    content: a,
    width: 400,
    footerHide: !1,
    okText: '确定'
  }
  b && typeof b === 'function' && (c = b)
  b && typeof b === 'object' && (props = Vue.util.extend(props,b))
  c && (props.onOk = c)
  return confirm(props)
}

Dialog.confirm = function (a,b,c,d) {
  var props = {
    showCancel: !1,
    closable: !0,
    icon: 'confirm',
    title:'温馨提示',
    content: a,
    width: 400,
    footerHide: !1,
    showCancel: !0,
    okText: '确定',
    cancelText: '取消'
  }
  b && typeof b === 'function' && (d = c,c = b)
  b && typeof b === 'object' && (props = Vue.util.extend(props,b))
  c && (props.onOk = c)
  d && (props.onCancel = d)
  return confirm(props)
}

Dialog.info = function (a,b,c) {
  return Dialog.start(a,b,c,'info')
}

Dialog.success = function (a,b,c) {
  return Dialog.start(a,b,c,'success')
}

Dialog.warning = function (a,b,c) {
  return Dialog.start(a,b,c,'warning')
}

Dialog.error = function (a,b,c) {
  return Dialog.start(a,b,c,'error')
}

Vue.prototype.$Dialog = Dialog

export default Dialog;